// SELECT * FROM production.matrixbox where keyword like '%g%';

// $.get('http://http://api.juzhen05.com/admin/matrixbox/list?serch=和昌)        所有数据


var path = require('path')
var routerApi = require('../../../utils/routeString.js')(__filename, __dirname);

var SqlHelper = require('../../../utils/sqlHelper.js')

var list = async function (req, res, next) {
    var body = req.body || req.query;

    if (body.keyword) {

        try {
            var sqlHelper = new SqlHelper('matrixbox');
            var sqlStr = 'SELECT * FROM production.matrixbox where keyword like "%' + body.keyword + '%"' + ((body.offset > -1 && body.limit > 0) ? (' limit ' + body.offset + ',' + body.limit) : (''));

            var result = await sqlHelper.asyncQuery(sqlStr);
            var countStr = 'SELECT count(*)num FROM production.matrixbox where keyword like "%' + body.keyword + '%"';
            var result2 = await sqlHelper.asyncQuery(countStr) //results[0].num
            return res.send({ code: 1, result: { list: result, count: result2[0].num } });
        } catch (error) {
            return res.send({ code: 0, msg: error.message });
        }
    } else {
        return res.send({ code: 0, msg: "您未输入关键字" });
    }


}


server.get({ path: routerApi, name: routerApi }, list)
